{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "34aa8b48",
   "metadata": {},
   "outputs": [],
   "source": [
    "import  json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a2749cee",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "87cc2bbf",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = dict([('aa',1),('bb',2)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8716b683",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'aa': 1, 'bb': 2}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6978d1e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "j_data = json.dumps(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c651a853",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"aa\": 1, \"bb\": 2}'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "j_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "dd5687f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(j_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cdebcb50",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "097848c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('json_test.json', 'w', encoding='utf8') as w:\n",
    "    w.write(j_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "73074882",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<_io.TextIOWrapper name='json_test.json' mode='w' encoding='utf8'>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "0f98be19",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'E:\\\\pycharm_out\\\\yufa\\\\git_test'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.path.abspath('')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "06881cc4",
   "metadata": {},
   "outputs": [],
   "source": [
    "os.startfile(os.path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "903c95a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "os.startfile(os.path.abspath(''))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "0f0b3174",
   "metadata": {},
   "outputs": [],
   "source": [
    "aa = {'a1':{'b1':[1,2,3,4]},'c1':1}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "041d378c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'a1': {'b1': [1, 2, 3, 4]}, 'c1': 1}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "e2021569",
   "metadata": {},
   "outputs": [],
   "source": [
    "aa_json = json.dumps(aa)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "66c1696e",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('json_test.json', 'w', encoding='utf8') as w:\n",
    "    w.write(aa_json)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "cc56b6e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "0b3a71f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"a1\": {\"b1\": [1, 2, 3, 4]}, \"c1\": 1}'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with open('json_test.json', 'r', encoding='utf8') as r:\n",
    "    data = r.read()\n",
    "data  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "81706fb0",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_loads = json.loads(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "3e19f412",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'a1': {'b1': [1, 2, 3, 4]}, 'c1': 1}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_loads"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "6915d36c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(data_loads)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "59b3e397",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_eval = eval(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "ab58e71e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'a1': {'b1': [1, 2, 3, 4]}, 'c1': 1}"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_eval"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "fe90b3e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(data_eval)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb284d50",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
